$(document).ready(function () {
    $("#promptMessage").load("promptMessage");
    getSystemConfigValue('backLog', 'backLog', 'bs-navbar');
    doGetWorkState();
})

function doGetWorkState() {
    $.post("doGetWorkState", function (result) {
        if (result.state == 1) {
            var list = result.data;
            $(".setUp").attr("name", list[0].workStateValue);
        } else {
            showMessage("获取紧急提醒数据失败");
        }
    })
}

function showImage(ImageOne, ImageTwo) {
    if (ImageOne) {
        $('#' + ImageOne).show();
    }
    if (ImageTwo) {
        $('#' + ImageTwo).hide();
    }
}

function getSystemConfigValue(skipUrl, skipID, ID) {
    if (skipUrl && skipID) {
        $('.activeLi').removeClass("activeLi");
        $('.active').removeClass("active");
        $("#" + skipID).addClass("activeLi");
        var $div = $("#" + ID);
        if ($div.css("height") == "241px") {
            $($div).css('height', '1px');
        }
        $("#promptMessage").hide();
        $("#iframe").attr("src", skipUrl);
    } else {
        showMessage("正在建设中...");
    }
}

function showMessage(message, num, methodName) {
    $("#promptMessage").show();
    $("#promptMsg").html(message);
    $("#doubleSure").hide();
    $("#onlySure").show();
    if (num == 1) {
        $("#sureBtn").attr("onclick", methodName);
        $("#onlySure").hide();
        $("#doubleSure").show();
    }
}

/***
 *读取指定的Cookie值
 *@param {string} cookieName Cookie名称
 */
function ReadCookie(cookieName) {
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf(cookieName);
    if (ind == -1 || cookieName == "") return "";
    var ind1 = theCookie.indexOf(';', ind);
    if (ind1 == -1) ind1 = theCookie.length;
    /*读取Cookie值*/
    return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function toSetUp() {
    $('.activeLi').removeClass("activeLi");
    $("#iframe").attr("src", "setUp");
}

function logOut() {
    showMessage("确定要退出吗", 1, "toSignOut()");
}

function toSignOut() {
    location.href = "signOut";
}

function hidePrompt() {
    $("#promptMessage").hide();
}

function delVersionsAssignment(productId, productName, versionsId) {
    var contentWindow = $("#iframe") && $("#iframe")[0] && $("#iframe")[0].contentWindow;
    if (contentWindow && typeof contentWindow.delVersionsAssignment === 'function') {
        return contentWindow.delVersionsAssignment(productId, productName, versionsId);
    } else {
        return undefined;
    }
}

function deleteModule(Index, productID, productName, productVersionID, productVersionName, moduleID) {
    var contentWindow = $("#iframe") && $("#iframe")[0] && $("#iframe")[0].contentWindow;
    if (contentWindow && typeof contentWindow.deleteModule === 'function') {
        return contentWindow.deleteModule(Index, productID, productName, productVersionID, productVersionName, moduleID);
    } else {
        return undefined;
    }
}

function deleteSprint(sprintId, productVersionID) {
    var contentWindow = $("#iframe") && $("#iframe")[0] && $("#iframe")[0].contentWindow;
    if (contentWindow && typeof contentWindow.deleteSprint === 'function') {
        return contentWindow.deleteSprint(sprintId, productVersionID);
    } else {
        return undefined;
    }
}

function deleteUser(ID) {
    var contentWindow = $("#iframe") && $("#iframe")[0] && $("#iframe")[0].contentWindow;
    if (contentWindow && typeof contentWindow.deleteUser === 'function') {
        return contentWindow.deleteUser(ID);
    } else {
        return undefined;
    }
}

function deleteProduct(productID, status) {
    if (status == "Yes") {
        $.post("doDeleteProduct", {"productID": productID}, function (result) {
            if (result.state == "Success") {
                $("#product").click();
            } else {
                showMessage("删除失败");
                $("#iframe").contents().find(".manangeProduct").hide();
            }
        })
    }
}

function toAddSprint(productVersionID) {
    $("#sprint").click();
    $("#iframe").attr("name", productVersionID);
}

function toAddProduct(productID) {
    $("#product").click();
    $("#iframe").attr("name", productID);
}

function hideShowMenu(state) {
    if (state == "open") {
        $("#iframe").contents().find("#BackLogLeftMenu").show();
        $("#hideShowMainMenuBtn").attr('onclick', 'hideShowMenu("hide")');
        $("#hideShowMainMenuBtn").css('left', '20pt');
        $("#iframe").contents().find("#BackLogLeftMenu").css('width', '420pt');
        $("#iframe").contents().find("#BackLogRightMenu").attr('hidden', 'hidden');
        $("#iframe").contents().find("#backLogPage").click();

    } else if (state == "hide") {
        $("#iframe").contents().find("#BackLogLeftMenu").hide();
        $("#hideShowMainMenuBtn").attr('onclick', 'hideShowMenu("open")');
        $("#hideShowMainMenuBtn").css('left', '20pt');
        $("#iframe").contents().find("#BackLogRightMenu").attr('hidden', false);
        $("#iframe").contents().find("#BackLogRightMenu").css('position', 'false');
        $("#iframe").contents().find("#BackLogRightMenu").css('margin-left', '0pt');
    }

}